﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Mobile_H.Master" Inherits="System.Web.Mvc.ViewPage<Bias_Stock.Models.CountCartModel.data_ds>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Count_Tag
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <style type="text/css">
        input.ui-input-text
        {
            height: 25px;
            background-color: #FFF;
            border: 1px solid #bbbbbb;
            -webkit-box-shadow: 0 1px 3px rgba(0,0,0,0.3) inset;
            -moz-box-shadow: 0 1px 3px rgba(0,0,0,0.3) inset;
            box-shadow: 0 1px 3px rgba(0,0,0,0.3) inset;
            width: 95%;
        }
        
        .hide
        {
            display: none;
        }
        tr
        {
            height: 35px;
            text-align: right;
            background-color: #fff;
        }
        tr.dis
        {
            background-color: #FFFFC2;
        }
    </style>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="FeaturedContent" runat="server">
    <div style="background-color: #8094AE; height: 50px; margin-top: 0px;">
        <h2 style="color: White; vertical-align: middle;">
            &nbsp;COUNT</h2>
    </div>
    <div id="page1">
        <table style="width: 100%; font-size: medium; color: #004080; padding: 5px; font-weight: bold;">
            <tr class="dis">
                <td style="width: 35%; text-align: right;">
                    DATE : &nbsp;
                </td>
                <td style="text-align: left;">
                    &nbsp;&nbsp;
                    <%= WinNemoLib.DateUtil.ToDisplayDate(DateTime.Now) %>
                </td>
            </tr>
            <tr class="dis">
                <td>
                    EMP : &nbsp;
                </td>
                <td style="text-align: left;">
                    &nbsp;&nbsp;
                    <%= User.Identity.Name.ToString() %>
                </td>
            </tr>
            <tr id="area" class="dis">
                <td>
                    Area : &nbsp;
                </td>
                <td style="text-align: left;">
                    &nbsp;&nbsp;<%: Model._area %>
                </td>
            </tr>
            <tr class="dis">
                <td class="dis">
                    Cart : &nbsp;
                </td>
                <td style="text-align: left;">
                    &nbsp;&nbsp;<%: Model._cart %>
                </td>
            </tr>
            <tr>
                <td>
                    Tag : &nbsp;
                </td>
                <td style="text-align: left;">
                    <input type="password" class="ui-input-text" onkeypress="javascript:calltoJSFunction()" />
                </td>
            </tr>
        </table>
        <div style="float: left">
            <input type="button" id="back" value="Back" style="width: 40%" /></div>
        <div style="float: right; width: 45%">
            <input type="button" id="blank" value="&nbsp;Blank Cart&nbsp;" style="width: 100%" /></div>
    </div>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="ScriptsSection" runat="server">
    <% if (false)
       { %>
    <script src="../../Scripts/jquery-1.7.1.js" type="text/javascript"></script>
    <% } %>
    <script type="text/jscript">

//        function Comp_cart() {
//            var cartno = '<%: Model._cart %>';
//            $.post('<%= Url.Action("GetCartno") %>' + '?tag=' + encodeURIComponent($("input.ui-input-text").val())
//            , function (data) {
//                if (cartno != data) {
//                    alert("Cart Not Correct");
//                    return false;
//                }
//                return true;
//            });
//        }


        function Match_Cart() {
            $.post('<%= Url.Action("GetTag") %>' + '?tag=' + encodeURIComponent($("input.ui-input-text").val())
        , function (data) {
            if (data != "") {
                alert(data); 
                $("input.ui-input-text").val("");
                return;
            }
            else {
              //  Comp_cart()
                window.location = '<%= Url.Action("Tag_Cart") %>' + '?tag=' + encodeURIComponent($("input.ui-input-text").val()) + "&area=" + '<%: Model._area %>' + '&cartno=' + '<%: Model._cart %>';
            }
        });

        }
        function calltoJSFunction(e) {
            if (window.event) {
                e = window.event;
            }

            if (e.keyCode == 13) {
                if ($("input.ui-input-text").val() == "") {
                    alert("Input Data");
                    return;
                }
                //--//
                if ($("input.ui-input-text").val() == "") {
                    alert("Input Tag");
                    return;
                } else Match_Cart();
                //--//
            }
        }

        $(function () {

            $("input.ui-input-text").focus();
            $("#back").click(function () {
                window.location = '<%= Url.Action("Count_Cart") %>' + '?area=' + '<%: Model._area %>'
            });

            $("#blank").click(function () {
                //            if ($("input.ui-input-text").val() == "") {
                //                alert("Input Tag");
                //                return;
                //            }
                if (!confirm("Confirm Blank Cart?")) {
                    //Match_Cart();
                    return false;
                }
                Save_blank();
            });



            function Save_blank() {
                var dataForSubmit = new Array();
                dataForSubmit.push({
                    _area: '<%: Model._area %>'
                });
                var getUsersUrl = '<%= Url.Action("Blank_Cart") %>';
                callScriptMethod(getUsersUrl, { theData: dataForSubmit, cartno: '<%:Model._cart %>' });
            }


            $("input.ui-input-text").on("keydown", function (event) {

                if (event.keyCode == 13 || event.which == 13) {
                    Match_Cart();
                }
            });


            function callScriptMethod(url, jsonObject, action, callback, async) {

                callback = callback || function () { };
                async = (async == null || async);

                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: url,
                    data: JSON.stringify(jsonObject),
                    dataType: "json",
                    async: async,
                    success: function (data) {

                        if (data.success != "1") {
                            alert(data.message);
                        } else {

                            alert("Save Complete");
                            window.location = '<%= Url.Action("Count_Cart") %>' + '?area=' + '<%: Model._area %>'
                        }
                    },
                    error: function (xhr, status, error) {
                        var err = xhr.responseText;
                        alert(err.Message);
                    }
                });
            }

        });
    </script>
</asp:Content>
